/*
 * @Descripttion: 会员套餐列表配置
 * @version: 电子名片2.0
 * @Author: 冯健
 * @Date: 2020-11-24 10:41:12
 * @LastEditors: 冯健
 * @LastEditTime: 2020-12-09 17:54:45
 */
const isTrue = true;
export const listHedar = [
  { label: '版本编号', prop: 'id'},
  { label: '版本号', prop: 'appVersion' },
  { 
    label: '更新类型', prop: 'appType',
    show: {
      '1': '强制更新',
      '2': '一般更新',
      '3': '可忽略更新'
    } 
  },
  { 
    label: '适配终端', prop: 'appTerminal',
    show: {
      '1': 'IOS',
      '2': 'Android',
      '3': 'HarmonyOS'
    }
  },
  { label: '修改人', prop: 'modifierName' },
  { label: '修改时间', prop: 'gmtModified', },
  { label: '操作', prop: 'operate', isTemplate: true, fixed: 'right' }
]
export const searchs = [
  { type: 'input', key: 'version', value: '', placeholder: '版本名' },
]

function transformParams(editList, detail) {
  editList.forEach(item => {
    if (item.transform) {
      item.transform(detail);
    } else {
      item.value = detail[item.key]
    }
  })
}

function createVersion() {
  const _v = [];
  for (let i = 0; i < 4; i++) {
    _v.push({key: i, value: i})
  }
  return [
    { key: 'value1', value: '', data: _v, tag: 'V' },
    { key: 'value2', value: '', data: _v, tag: '.' },
    { key: 'value3', value: '', data: _v, tag: '.' }
  ];
}
export function createEdit(detail=null) {
  const editList = [
    {
      type: 'select-group',
      key: 'appVersion',
      label: '版本号',
      have: isTrue,
      data: createVersion(),
      transform(data) {
        data.appVersion.split('.').forEach((item, index) => {
          this.data[index].value = item;
        })
      },
      setParams() {
        let _appVersions = [];
        this.data.forEach(item => {
          _appVersions.push(item.value);
        })
        return { appVersion: _appVersions.join('.') };
      }
    },
    {
      type: 'radio', key: 'appType', label: '更新类型', have: isTrue, value: '',
      data: [
        { title: '强制更新', value: 1 },
        { title: '一般更新', value: 2 },
        { title: '可忽略更新', value: 3 }
      ],
    },
    {
      type: 'radio', key: 'appTerminal', label: '适配终端', have: isTrue, value: '',
      data: [
        { title: 'IOS', value: 1 },
        { title: 'Android', value: 2 },
        { title: 'HarmonyOS', value: 3 }
      ]
    },
    { type: 'input', key: 'updateAddress', label: '更新地址', placeholder: '请输入', value: '' },
    { type: 'textarea', key: 'versionDescribed', label: '版本描述', placeholder: '请输入', value: '' }
  ]
  if (detail) {
    transformParams(editList, detail);
  }
  return editList
} 